import 'package:flutter/material.dart';
import 'package:thatsfelix/pages/HomePage.dart';
import 'package:thatsfelix/pages/MyPage.dart';
import 'package:thatsfelix/pages/SearchPage.dart';
import 'package:thatsfelix/pages/Travel.dart';
import 'package:thatsfelix/utils/ScreenAdapter.dart';

class TabNavigator extends StatefulWidget {
  @override
  _TabNavigator createState() => _TabNavigator();
}

class _TabNavigator extends State<TabNavigator> {
  final _defaultColor = Colors.grey;
  final _activeColor = Color(0xff163f3b);
  int _currentIndex = 0;
  final PageController _controller = PageController(
    initialPage: 0,
  );

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Scaffold(
      body: PageView(
        controller: _controller,
        children: <Widget>[HomePage(), SearchPage(), TravelPage(), MyPage()],
      ),
      bottomNavigationBar: BottomNavigationBar(
          currentIndex: _currentIndex,
          onTap: (index) {
            _controller.jumpToPage(index);
            setState(() {
              _currentIndex = index;
            });
          },
          selectedFontSize: ScreenAdapter.width(24),
          unselectedFontSize: ScreenAdapter.width(24),
          type: BottomNavigationBarType.fixed,
          items: [
            BottomNavigationBarItem(
                icon: Icon(Icons.home, color: _defaultColor),
                activeIcon: Icon(Icons.home, color: _activeColor),
                title: Text("首页",
                    style: TextStyle(color: _currentIndex != 0 ? _defaultColor : _activeColor))),
            BottomNavigationBarItem(
                icon: Icon(Icons.search, color: _defaultColor),
                activeIcon: Icon(Icons.search, color: _activeColor),
                title: Text("搜索",
                    style: TextStyle(color: _currentIndex != 1 ? _defaultColor : _activeColor))),
            BottomNavigationBarItem(
                icon: Icon(Icons.camera_alt, color: _defaultColor),
                activeIcon: Icon(Icons.camera_alt, color: _activeColor),
                title: Text("旅拍",
                    style: TextStyle(color: _currentIndex != 2 ? _defaultColor : _activeColor))),
            BottomNavigationBarItem(
                icon: Icon(Icons.account_circle, color: _defaultColor),
                activeIcon: Icon(Icons.account_circle, color: _activeColor),
                title: Text("我的",
                    style: TextStyle(color: _currentIndex != 3 ? _defaultColor : _activeColor))),
          ]),
    );
  }
}
